package com.sjh.lib_app.statusMananger.defWidget

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.sjh.lib_app.R
import com.sjh.lib_app.statusMananger.StatusManager
import com.sjh.lib_app.statusMananger.StatusView
import com.sjh.lib_app.utils.dip

/**
 * 加载数据出现错误
 * @author SunJH
 * @date 2020/3/28/28
 */
class LoadErrorStatusView : StatusView() {
    companion object {
        const val LOAD_ERROR_RELOAD = "LoadErrorReload"
    }

    override fun createView(context: Context, statusManager: StatusManager): View {
        return LinearLayout(context).apply {
            orientation = LinearLayout.VERTICAL
            layoutParams = ViewGroup.LayoutParams(-1, -1)
            gravity = Gravity.CENTER

            val tv = TextView(context)
            val iv = ImageView(context)
            val tvLoading = TextView(context)
            tvMessage = tv
            tv.apply {
                layoutParams = LinearLayout.LayoutParams(-2, -2).apply {
                    topMargin = dip(32)
                }
                text = defaultErrorMsg
                setTextColor(context.getColor(R.color.app_font_999999))
            }

            iv.apply {
                layoutParams = LinearLayout.LayoutParams(dip(300), dip(212))
                setImageResource(R.drawable.app_bg_error)
            }
            tvLoading.apply {
                layoutParams = LinearLayout.LayoutParams(-2, -2).apply {
                    topMargin = dip(13)
                }
                text = "点击重新加载"
                setTextColor(context.getColor(R.color.app_d33))
            }
            addView(iv)
            addView(tv)
            addView(tvLoading)
            setOnClickListener { statusManager.setOnClickEvent(LOAD_ERROR_RELOAD) }
        }
    }

}